﻿(function () {
    "use strict";

    var months = new WinJS.Binding.List();

    WinJS.UI.Pages.define("/pages/calendar/mainCalendar/mainCalendar.html", {
        ready: function (element, options) {
            element.querySelector('#ListView').addEventListener('iteminvoked', function (e) {
                WinJS.Navigation.navigate('/pages/calendar/weekCalendar/weekCalendar.html', { item: e.detail.itemPromise._value.data });
            });
            initPage();
            
            document.querySelector("#firstSubHeader").addEventListener("click", function () {
                DateUtility.CurrentYear--;
                initPage();
            });
            document.querySelector("#thirdSubHeader").addEventListener("click", function () {
                DateUtility.CurrentYear++;
                initPage();
            });
        }
    });


    var initPage = function(){
        var date = new Date(DateUtility.CurrentYear, DateUtility.CurrentMonth, DateUtility.CurrentDay);

        months.splice(0, months.length);
        getElements();

        document.querySelector("#secondSubHeader").innerText = date.toString("yyyy");
    }
    

    var getElements = function () {

        var i = 0;
        var date = new Date(DateUtility.CurrentYear, DateUtility.CurrentMonth);
        for (i = 0 ; i < 12; i++) {
            date.setMonth(i);
            months.push({ month: date.toString("MMMM"), monthInt: i });
        }
    }

    var publicMembres = {
        months: months
    };


    WinJS.Namespace.define("MainCalendar", publicMembres);

})();
